package com.tiza.xiaoyoubao.ui.fragment;

import android.content.Intent;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.orhanobut.hawk.Hawk;
import com.squareup.picasso.Picasso;
import com.tianze.library.base.BaseFragment;
import com.tianze.library.view.SimpleDialog;
import com.tiza.xiaoyoubao.MainActivity;
import com.tiza.xiaoyoubao.R;
import com.tiza.xiaoyoubao.app.Constants;
import com.tiza.xiaoyoubao.app.UIHelper;
import com.tiza.xiaoyoubao.entity.InsertTaskInfo;
import com.tiza.xiaoyoubao.entity.TaskOperateInfo;
import com.tiza.xiaoyoubao.entity.TaskOrderInfo;
import com.tiza.xiaoyoubao.entity.UserInfo;
import com.tiza.xiaoyoubao.net.ApiHttpClient;
import com.tiza.xiaoyoubao.net.JsonCallback;
import com.tiza.xiaoyoubao.net.ResponseInfo;
import com.tiza.xiaoyoubao.utils.BitmapUtils;
import com.tiza.xiaoyoubao.utils.DateUtils;
import com.tiza.xiaoyoubao.utils.ImageUtils;
import com.tiza.xiaoyoubao.utils.OtherUtils;

import java.io.File;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;

import butterknife.BindView;
import butterknife.OnClick;
import me.nereo.multi_image_selector.MultiImageSelectorActivity;
import okhttp3.Call;
import okhttp3.Request;

import static android.app.Activity.RESULT_OK;

/**
 * Created by mapple on 17/4/14.
 */

public class OperationTaskFragment extends BaseFragment {

    TaskOrderInfo mOrderInfo = Hawk.get(Constants.KEY_TASKOEDER_INFO, (TaskOrderInfo) null);
    InsertTaskInfo mInsertTaskInfo = Hawk.get(Constants.KEY_INSERTTASK_INFO, (InsertTaskInfo) null);
    UserInfo userInfo = Hawk.get(Constants.KEY_USER_INFO, (UserInfo) null);
    private TaskOperateInfo taskOperateInfo;
    @BindView(R.id.iv_image)
    ImageView iv_image;
    @BindView(R.id.iv_image2)
    ImageView iv_image2;
    @BindView(R.id.iv_image3)
    ImageView iv_image3;
    @BindView(R.id.tv_showPrice)
    TextView tv_showPrice;
    @BindView(R.id.tv_comit)
    TextView tv_comit;
    @BindView(R.id.tv_shopName)
    TextView tv_shopName;
    @BindView(R.id.tv_shopName1)
    TextView tv_shopName1;
    @BindView(R.id.tv_shopDescribe)
    TextView tv_shopDescribe;
    @BindView(R.id.tv_keyWord)
    TextView tv_keyWord;
    @BindView(R.id.tv_cJPrice)
    TextView tv_cJPrice;
    @BindView(R.id.tv_cJPrice1)
    TextView tv_cJPrice1;
    @BindView(R.id.tv_cJPrice2)
    TextView tv_cJPrice2;
    @BindView(R.id.tv_num)
    TextView tv_num;
    @BindView(R.id.tv_num1)
    TextView tv_num1;
    @BindView(R.id.tv_num2)
    TextView tv_num2;
    @BindView(R.id.tv_taskType)
    TextView tv_taskType;
    @BindView(R.id.tv_buyNumber)
    TextView tv_buyNumber;
    @BindView(R.id.tv_receiving)
    TextView tv_receiving;
    @BindView(R.id.tv_location)
    TextView tv_location;
    @BindView(R.id.tv_city)
    TextView tv_city;
    @BindView(R.id.tv_priceInterval)
    TextView tv_priceInterval;
    @BindView(R.id.tv_orderMessage)
    TextView tv_orderMessage;
    @BindView(R.id.tv_additionalRequest)
    TextView tv_additionalRequest;
    @BindView(R.id.iv_openTaoBao)
    ImageView iv_openTaoBao;
    @BindView(R.id.tv_comit_two)
    TextView tv_comit_two;
    @BindView(R.id.tv_referPrice)
    TextView tv_referPrice;
    @BindView(R.id.view1)
    View view1;
    @BindView(R.id.view2)
    View view2;
    @BindView(R.id.view3)
    View view3;
    @BindView(R.id.view_fuJia1_header)
    View view_fuJia1_header;
    @BindView(R.id.view_fuJia1_footer)
    View view_fuJia1_footer;
    @BindView(R.id.view_fuJia2_header)
    View view_fuJia2_header;
    @BindView(R.id.view_fuJia2_footer)
    View view_fuJia2_footer;
    @BindView(R.id.view_fuJia2)
    View view_fuJia2;
    @BindView(R.id.iv_searchResult)
    ImageView iv_searchResult;
    @BindView(R.id.iv_shop1)
    ImageView iv_shop1;
    @BindView(R.id.iv_shop2)
    ImageView iv_shop2;
    @BindView(R.id.iv_storeShop1)
    ImageView iv_storeShop1;
    @BindView(R.id.iv_storeShop2)
    ImageView iv_storeShop2;
    @BindView(R.id.iv_targetGoods_Start)
    ImageView iv_targetGoods_Start;
    @BindView(R.id.iv_targetGoods_End)
    ImageView iv_targetGoods_End;
    @BindView(R.id.iv_fuJia1_header)
    ImageView iv_fuJia1_header;
    @BindView(R.id.iv_fuJia1_footer)
    ImageView iv_fuJia1_footer;
    @BindView(R.id.iv_fuJia2_header)
    ImageView iv_fuJia2_header;
    @BindView(R.id.iv_fuJia2_footer)
    ImageView iv_fuJia2_footer;
    @BindView(R.id.iv_chat)
    ImageView iv_chat;
    @BindView(R.id.iv_orderPay)
    ImageView iv_orderPay;
    @BindView(R.id.et_money)
    EditText et_money;
    private String taskState, orderFlag;
    /**
     * 选择图片的返回码
     */
    public final static int SELECT_IMAGE_RESULT_CODE = 200;
    String[] proj = {MediaStore.MediaColumns.DATA};
    private String ivState;
    private File imageFile, imageSearchResult, imageShop1, imageShop2, imageStoreShop1, imageStoreShop2, imageTargetGoodsStart, imageTargetGoodsEnd, imageFuJia1Header, imageFuJia1Footer, imageFuJia2Header, imageFuJia2Footer, imageChat, imageOrderPay;
    private Bitmap bitmapSearchResult, bitmapShop1, bitmapShop2, bitmapStoreShop1, bitmapStoreShop2, bitmapTargetGoodsStart, bitmapTargetGoodsEnd, bitmapFuJia1Header, bitmapFuJia1Footer, bitmapFuJia2Header, bitmapFuJia2Footer, bitmapChat, bitmapOrderPay;
    /**
     * 当前选择的图片的路径
     */
    public String mImagePath;
    private String imageFilePath;
    private final int REQUEST_IMAGE = 2;
    private int maxNum = 0;
    private ArrayList<String> mSelectPath;
    private List<Bitmap> bitmapList = new ArrayList<>();
    //是否选择的标记
    private boolean flag = true;
    private List<String> finalSelectPaths = new ArrayList<>();
    private int step = 0;
    DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    private Date date1;
    ArrayList<Date> dateList = new ArrayList<>();

    private String etMoney;
    Bundle args;
    private String way, cid, orderid, addtime, buyerid, taskCode, reason, account, sellerID, endTime;
    private boolean isOverTime = false;
    Timer timer = new Timer();
    Date date;
    Date date2;
    long diff;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        args = getArguments();
        way = args.getString("way");
        if (way.equals("1")) {
            taskState = "1";
            cid = String.valueOf(mInsertTaskInfo.getCid());
            orderid = mInsertTaskInfo.getOrderid();
            buyerid = mInsertTaskInfo.getBuyerid();
            taskCode = mInsertTaskInfo.getTaskCode();
            account = mInsertTaskInfo.getAccount();
            sellerID = mInsertTaskInfo.getSellerid();
            addtime = DateUtils.getDateToStringSec(mInsertTaskInfo.getAddtime());
            endTime = DateUtils.getDateToStringSec(mInsertTaskInfo.getEndtime());
            timer.schedule(task, 1000, 1000);
        } else if (way.equals("2")) {
            taskState = "2";
            taskOperateInfo = (TaskOperateInfo) args.getSerializable("info");
            cid = String.valueOf(taskOperateInfo.getId());
            orderid = taskOperateInfo.getOrderid();
            taskCode = taskOperateInfo.getTaskCode();
            account = taskOperateInfo.getAccount();
            sellerID = taskOperateInfo.getSellerId();
            addtime = DateUtils.getDateToStringSec(taskOperateInfo.getAddTime());
            endTime = DateUtils.getDateToStringSec(taskOperateInfo.getEndTime());
            timer.schedule(task, 1000, 1000);
        }
    }


    TimerTask task = new TimerTask() {
        @Override
        public void run() {

            mActivity.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    try {
                        date = df.parse(df.format(new Date()));
                        date2 = df.parse(endTime);

                    } catch (ParseException e) {
                        e.printStackTrace();
                    }
                    diff = (date2.getTime() - date.getTime()) / 1000;
                    int mm = (int) diff;
                    tv_comit.setText("提交任务:" + "(任务剩余时间 " + mm + "S)");
                    if (diff <= 0) {
                        timer.cancel();
                        isOverTime = true;
                        //cancelTask();
                    }
                }
            });
        }
    };

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_operation_task;
    }

    //TODO 需要加判断
    @Override
    protected void initData() {
        try {
            date1 = df.parse(addtime);
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }

    @OnClick({
            R.id.view_comit,
            R.id.iv_openTaoBao,
            R.id.iv_searchResult,
            R.id.iv_shop1,
            R.id.iv_shop2,
            R.id.iv_storeShop1,
            R.id.iv_storeShop2,
            R.id.iv_targetGoods_Start,
            R.id.iv_targetGoods_End,
            R.id.iv_fuJia1_header,
            R.id.iv_fuJia1_footer,
            R.id.iv_fuJia2_header,
            R.id.iv_fuJia2_footer,
            R.id.iv_chat,
            R.id.iv_orderPay,
            R.id.view_save,
            R.id.view_comit_two,
            R.id.view_comit_three,
            R.id.tv_contactShop,
            R.id.button
    })
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.view_comit:
                if (isOverTime) {
                    toast("无法提交，任务已超时");
                } else {
                    String message = checkMessage();
                    if (!TextUtils.isEmpty(message)) {
                        toast(message);
                        return;
                    }
                    if (TextUtils.isEmpty(mOrderInfo.getUrl2()) && TextUtils.isEmpty(
                            mOrderInfo.getUrl3())) {
                        insertDianFuTask2();
                    } else if (!TextUtils.isEmpty(mOrderInfo.getUrl2()) && TextUtils.isEmpty(
                            mOrderInfo.getUrl3())) {
                        insertDianFuTask2Six();

                    } else if (!TextUtils.isEmpty(mOrderInfo.getUrl2()) && !TextUtils.isEmpty(
                            mOrderInfo.getUrl3())) {
                        insertDianFuTask2Eight();
                    }
                }
                break;
            case R.id.iv_openTaoBao:
                OtherUtils.copy(mOrderInfo.getKeywords(), mActivity);
                try {
                    PackageManager packageManager = mActivity.getPackageManager();
                    Intent intent = new Intent();
                    intent = packageManager.getLaunchIntentForPackage("com.taobao.taobao");
                    startActivity(intent);
                } catch (Exception e) {
                    e.printStackTrace();
                    toast("您未安装手机淘宝客户端,请先安装");
                }
                break;
            case R.id.button:
               toast("功能部署中");
                break;
            case R.id.iv_searchResult:
                upLoadImage("searchResult");
                break;
            case R.id.iv_shop1:
                upLoadImage("shop1");
                break;
            case R.id.iv_shop2:
                upLoadImage("shop2");
                break;
            case R.id.iv_storeShop1:
                upLoadImage("storeShop1");
                break;
            case R.id.iv_storeShop2:
                upLoadImage("storeShop2");
                break;
            case R.id.iv_targetGoods_Start:
                upLoadImage("targetGoodsStart");
                break;
            case R.id.iv_targetGoods_End:
                upLoadImage("targetGoodsEnd");
                break;
            case R.id.iv_fuJia1_header:
                upLoadImage("fuJia1Header");
                break;
            case R.id.iv_fuJia1_footer:
                upLoadImage("fuJia1Footer");
                break;
            case R.id.iv_fuJia2_header:
                upLoadImage("fuJia2Header");
                break;
            case R.id.iv_fuJia2_footer:
                upLoadImage("fuJia2Footer");
                break;
            case R.id.iv_chat:
                upLoadImage("chat");
                break;
            case R.id.iv_orderPay:
                upLoadImage("orderPay");
                break;
            case R.id.tv_contactShop:
              toast("功能部署中");
                break;
            case R.id.view_save:
                maxNum = 3;
                step = 1;
                selectGallery();
                break;
            case R.id.view_comit_two:
                if (TextUtils.isEmpty(mOrderInfo.getUrl2())) {
                    maxNum = 4;
                } else {
                    if (TextUtils.isEmpty(mOrderInfo.getUrl3())) {
                        maxNum = 6;
                    } else {
                        maxNum = 8;
                    }
                }
                step = 2;
                selectGallery();
                break;
            case R.id.view_comit_three:
                maxNum = 2;
                step = 3;
                selectGallery();
                break;
            default:
                break;
        }
    }

    @Override
    protected void initView() {
        if (way.equals("1")) {
            tv_shopName.setText(mOrderInfo.getShopName()
                                          .replaceFirst(mOrderInfo.getShopName().substring(0, 1),
                                                        "*"
                                          ));
            tv_shopName1.setText(mOrderInfo.getShopName()
                                           .replaceFirst(mOrderInfo.getShopName().substring(0, 1),
                                                         "*"
                                           ));
            if (mOrderInfo.getTitle().length() <= 15) {
                tv_shopDescribe.setText(mOrderInfo.getTitle());
            } else {
                tv_shopDescribe.setText("***" + mOrderInfo.getTitle()
                                                          .substring(15,
                                                                     mOrderInfo.getTitle().length()
                                                          ));
            }
            tv_keyWord.setText(mOrderInfo.getKeywords());
            tv_cJPrice.setText(mOrderInfo.getPrice());
            tv_referPrice.setText("应垫付金额参考:" + mOrderInfo.getPnumber() + "元(请按照实际垫付金额填写)");
            tv_num.setText(mOrderInfo.getNumber());
            tv_taskType.setText(mOrderInfo.getTypeName());
            tv_buyNumber.setText(mOrderInfo.getNumber());
            tv_showPrice.setText(mOrderInfo.getMobilePrice());
            Picasso.with(mActivity).load(ApiHttpClient.URL2 + mOrderInfo.getImages()).placeholder(
                    R.mipmap.rwcx_jiazaizhong).error(R.mipmap.rwcx_jiazaizhong).into(iv_image);
            if (mOrderInfo.getLocation().equals("xiaoliang")) {
                tv_receiving.setText("销量");
            } else if (mOrderInfo.getLocation().equals("zhitongche")) {
                tv_receiving.setText("直通车");
            } else if (mOrderInfo.getLocation().equals("zonghe")) {
                tv_receiving.setText("综合");
            }
            tv_location.setText(mOrderInfo.getReceiving());
            tv_city.setText(mOrderInfo.getCity());
            if (!TextUtils.isEmpty(mOrderInfo.getMinPrice())) {
                tv_priceInterval.setText(mOrderInfo.getMinPrice()+"-"+mOrderInfo.getMaxPrice());
            } else {
                tv_priceInterval.setText("");
            }
            tv_orderMessage.setText(mOrderInfo.getMessage());
            tv_additionalRequest.setText(mOrderInfo.getRemarks() + "");
            if (!TextUtils.isEmpty(mOrderInfo.getUrl2())) {
                view_fuJia1_header.setVisibility(View.VISIBLE);
                view_fuJia1_footer.setVisibility(View.VISIBLE);
                view1.setVisibility(View.VISIBLE);
                Picasso.with(mActivity).load(ApiHttpClient.URL2 + mOrderInfo.getImages2()).placeholder(
                        R.mipmap.rwcx_jiazaizhong).error(R.mipmap.rwcx_jiazaizhong).into(iv_image2);
                tv_cJPrice1.setText(mOrderInfo.getPrice2());
                tv_num1.setText(mOrderInfo.getNumber2());
                if (TextUtils.isEmpty(mOrderInfo.getUrl3())) {
                    tv_comit_two.setText("一次性上传6张图片");
                } else {
                    view_fuJia2_header.setVisibility(View.VISIBLE);
                    view_fuJia2_footer.setVisibility(View.VISIBLE);
                    view2.setVisibility(View.VISIBLE);
                    view3.setVisibility(View.VISIBLE);
                    tv_comit_two.setText("一次性上传8张图片");
                    tv_cJPrice2.setText(mOrderInfo.getPrice3());
                    tv_num2.setText(mOrderInfo.getNumber3());
                    Picasso.with(mActivity).load(ApiHttpClient.URL2 + mOrderInfo.getImages3
                            ()).placeholder(
                            R.mipmap.rwcx_jiazaizhong).error(R.mipmap.rwcx_jiazaizhong).into
                            (iv_image3);
                }
            }
        } else if (way.equals("2")) {
            tv_shopName.setText(taskOperateInfo.getShopName()
                                               .replaceFirst(taskOperateInfo.getShopName()
                                                                            .substring(0, 1), "*"));
            tv_shopName1.setText(taskOperateInfo.getShopName()
                                                .replaceFirst(taskOperateInfo.getShopName()
                                                                             .substring(0, 1),
                                                              "*"
                                                ));
            if (taskOperateInfo.getTitle().length() <= 15) {
                tv_shopDescribe.setText(taskOperateInfo.getTitle());
            } else {
                tv_shopDescribe.setText("***" + taskOperateInfo.getTitle()
                                                               .substring(15,
                                                                          taskOperateInfo.getTitle()
                                                                                         .length()
                                                               ));
            }
            tv_keyWord.setText(taskOperateInfo.getKeywords());
            tv_cJPrice.setText(taskOperateInfo.getPrice());
            tv_showPrice.setText(taskOperateInfo.getMobilePrice());
            tv_referPrice.setText("应垫付金额参考:" + taskOperateInfo.getPnumber() + "元(请按照实际垫付金额填写)");
            tv_num.setText(taskOperateInfo.getNumber());
            tv_taskType.setText(taskOperateInfo.getTypeName());
            tv_buyNumber.setText(taskOperateInfo.getNumber());
            if (taskOperateInfo.getLocation().equals("xiaoliang")) {
                tv_receiving.setText("销量");
            } else if (taskOperateInfo.getLocation().equals("zhitongche")) {
                tv_receiving.setText("直通车");
            } else if (taskOperateInfo.getLocation().equals("zonghe")) {
                tv_receiving.setText("综合");
            }
            Picasso.with(getActivity())
                   .load(ApiHttpClient.URL2 + taskOperateInfo.getImages())
                   .placeholder(R.mipmap.rwcx_jiazaizhong)
                   .error(R.mipmap.rwcx_jiazaizhong)
                   .into(iv_image);
            tv_location.setText(taskOperateInfo.getReceiving());
            tv_city.setText(taskOperateInfo.getCity());
            if (!TextUtils.isEmpty(taskOperateInfo.getMinPrice())) {
                tv_priceInterval.setText(
                        taskOperateInfo.getMinPrice()+"-"+taskOperateInfo.getMaxPrice());
            } else {
                tv_priceInterval.setText("");
            }
            tv_orderMessage.setText(taskOperateInfo.getMessage());
            tv_additionalRequest.setText(taskOperateInfo.getRemarks() + "");
            if (!TextUtils.isEmpty(taskOperateInfo.getUrl2())) {
                view_fuJia1_header.setVisibility(View.VISIBLE);
                view_fuJia1_footer.setVisibility(View.VISIBLE);
                view1.setVisibility(View.VISIBLE);
                tv_cJPrice1.setText(taskOperateInfo.getPrice2());
                tv_num1.setText(taskOperateInfo.getNumber2());
                Picasso.with(mActivity).load(ApiHttpClient.URL2 + taskOperateInfo.getImages2()).placeholder(
                        R.mipmap.rwcx_jiazaizhong).error(R.mipmap.rwcx_jiazaizhong).into(iv_image2);
                if (TextUtils.isEmpty(taskOperateInfo.getUrl3())) {
                    tv_comit_two.setText("一次性上传6张图片");
                } else {
                    view_fuJia2_header.setVisibility(View.VISIBLE);
                    view_fuJia2_footer.setVisibility(View.VISIBLE);
                    view2.setVisibility(View.VISIBLE);
                    view3.setVisibility(View.VISIBLE);
                    tv_comit_two.setText("一次性上传8张图片");
                    tv_cJPrice2.setText(taskOperateInfo.getPrice3());
                    tv_num2.setText(taskOperateInfo.getNumber3());
                    Picasso.with(mActivity).load(ApiHttpClient.URL2 + taskOperateInfo.getImages3
                            ()).placeholder(
                            R.mipmap.rwcx_jiazaizhong).error(R.mipmap.rwcx_jiazaizhong).into
                            (iv_image3);
                }
            }
        }
        intWatch();
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == SELECT_IMAGE_RESULT_CODE && resultCode == RESULT_OK) {
            String imagePath = "";
            Uri uri = null;
            if (data != null && data.getData() != null) {// 有数据返回直接使用返回的图片地址
                uri = data.getData();
                Cursor cursor = getActivity().getContentResolver().query(uri, proj, null, null,
                                                                         null
                );
                if (cursor == null) {
                    uri = ImageUtils.getUri(getActivity(), data);
                }
                imagePath = ImageUtils.getFilePathByFileUri(getActivity(), uri);
            } else {// 无数据使用指定的图片路径
                imagePath = mImagePath;
                int i = ImageUtils.parseImageDegree(imagePath);
                System.out.println("旋转的角度:" + i);

            }
            File file = new File(imagePath);
            Date date = new Date(file.lastModified());
            if ((date.getTime() - date1.getTime()) / 1000 < 0) {
                toast("请上传任务开始后的图片");
                return;
            }
            //获取图片缩略图，避免OOM
            Bitmap bitmap = ImageUtils.getImageThumbnail(imagePath, ImageUtils.getWidth(
                    getActivity().getApplicationContext()) / 3 - 5, ImageUtils.getWidth(
                    getActivity().getApplicationContext()) / 3 - 5);
            if (ivState.equals("searchResult")) {
                imageSearchResult = new File(imagePath);
                bitmapSearchResult = ImageUtils.rotateBitmap(bitmap,
                                                             ImageUtils.parseImageDegree(imagePath)
                );
                iv_searchResult.setImageBitmap(bitmapSearchResult);
            } else if (ivState.equals("shop1")) {
                imageShop1 = new File(imagePath);
                bitmapShop1 = ImageUtils.rotateBitmap(bitmap,
                                                      ImageUtils.parseImageDegree(imagePath)
                );
                iv_shop1.setImageBitmap(bitmapShop1);
            } else if (ivState.equals("shop2")) {
                imageShop2 = new File(imagePath);
                bitmapShop2 = ImageUtils.rotateBitmap(bitmap,
                                                      ImageUtils.parseImageDegree(imagePath)
                );
                iv_shop2.setImageBitmap(bitmapShop2);
            } else if (ivState.equals("storeShop1")) {
                imageStoreShop1 = new File(imagePath);
                bitmapStoreShop1 = ImageUtils.rotateBitmap(bitmap,
                                                           ImageUtils.parseImageDegree(imagePath)
                );
                iv_storeShop1.setImageBitmap(bitmapStoreShop1);
            } else if (ivState.equals("storeShop2")) {
                imageStoreShop2 = new File(imagePath);
                bitmapStoreShop2 = ImageUtils.rotateBitmap(bitmap,
                                                           ImageUtils.parseImageDegree(imagePath)
                );
                iv_storeShop2.setImageBitmap(bitmapStoreShop2);
            } else if (ivState.equals("targetGoodsStart")) {
                imageTargetGoodsStart = new File(imagePath);
                bitmapTargetGoodsStart = ImageUtils.rotateBitmap(bitmap,
                                                                 ImageUtils.parseImageDegree(
                                                                         imagePath)
                );
                if (imageTargetGoodsEnd != null) {
                    if ((new Date(imageTargetGoodsEnd.lastModified()).getTime() - new Date(
                            imageTargetGoodsStart.lastModified()).getTime()) / 1000 < 180) {
                        toast("请按要求浏览商品");
                        return;
                    }
                }
                iv_targetGoods_Start.setImageBitmap(bitmapTargetGoodsStart);
            } else if (ivState.equals("targetGoodsEnd")) {
                imageTargetGoodsEnd = new File(imagePath);
                bitmapTargetGoodsEnd = ImageUtils.rotateBitmap(bitmap, ImageUtils.parseImageDegree(
                        imagePath));
                if (imageTargetGoodsStart != null) {
                    if ((new Date(imageTargetGoodsEnd.lastModified()).getTime() - new Date(
                            imageTargetGoodsStart.lastModified()).getTime()) / 1000 < 180) {
                        toast("请按要求浏览商品");
                        return;
                    }
                }
                iv_targetGoods_End.setImageBitmap(bitmapTargetGoodsEnd);
            } else if (ivState.equals("fuJia1Header")) {
                imageFuJia1Header = new File(imagePath);
                bitmapFuJia1Header = ImageUtils.rotateBitmap(bitmap,
                                                             ImageUtils.parseImageDegree(imagePath)
                );
                iv_fuJia1_header.setImageBitmap(bitmapFuJia1Header);
            } else if (ivState.equals("fuJia1Footer")) {
                imageFuJia1Footer = new File(imagePath);
                bitmapFuJia1Footer = ImageUtils.rotateBitmap(bitmap,
                                                             ImageUtils.parseImageDegree(imagePath)
                );
                iv_fuJia1_footer.setImageBitmap(bitmapFuJia1Footer);
            } else if (ivState.equals("fuJia2Header")) {
                imageFuJia2Header = new File(imagePath);
                bitmapFuJia2Header = ImageUtils.rotateBitmap(bitmap,
                                                             ImageUtils.parseImageDegree(imagePath)
                );
                iv_fuJia2_header.setImageBitmap(bitmapFuJia2Header);
            } else if (ivState.equals("fuJia2Footer")) {
                imageFuJia2Footer = new File(imagePath);
                bitmapFuJia2Footer = ImageUtils.rotateBitmap(bitmap,
                                                             ImageUtils.parseImageDegree(imagePath)
                );
                iv_fuJia2_footer.setImageBitmap(bitmapFuJia2Footer);
            } else if (ivState.equals("chat")) {
                imageChat = new File(imagePath);
                bitmapChat = ImageUtils.rotateBitmap(bitmap,
                                                     ImageUtils.parseImageDegree(imagePath)
                );
                iv_chat.setImageBitmap(bitmapChat);
            } else if (ivState.equals("orderPay")) {
                imageOrderPay = new File(imagePath);
                bitmapOrderPay = ImageUtils.rotateBitmap(bitmap,
                                                         ImageUtils.parseImageDegree(imagePath)
                );
                iv_orderPay.setImageBitmap(bitmapOrderPay);
            }
        } else if (requestCode == REQUEST_IMAGE && resultCode == RESULT_OK) {
            mSelectPath = data.getStringArrayListExtra(MultiImageSelectorActivity.EXTRA_RESULT);
            for (String p : mSelectPath) {
                //加入最后选择的集合
                finalSelectPaths.add(p);
                Log.e("路径", p);
                //加载缩略图
                Bitmap bitmap = BitmapUtils.decodeSampledBitmapFromSd(p, 200, 240);
                bitmapList.add(bitmap);
            }
            for (int i = 0; i < finalSelectPaths.size(); i++) {
                File file = new File(finalSelectPaths.get(i));
                SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
                Date date = new Date(file.lastModified());
                dateList.add(date);
                Log.i("截图时间", "截图文件：" + finalSelectPaths.get(i));
                Log.i("截图时间", "截图时间：" + df.format(date));
            }
            Log.i("路径长度", "存储时间长度：" + dateList.size() + "");
            Log.i("路径长度", "路径长度：" + finalSelectPaths.size() + "");
            Log.i("路径长度", "bitmapList长度：" + bitmapList.size() + "");

            if (step == 1) {
                if ((dateList.get(0).getTime() - date1.getTime()) / 1000 > 0 && (dateList.get(1)
                                                                                         .getTime() - date1
                        .getTime()) / 1000 > 0 && (dateList.get(2)
                                                           .getTime() - date1.getTime()) / 1000 > 0) {
                    imageSearchResult = new File(finalSelectPaths.get(0));
                    imageShop1 = new File(finalSelectPaths.get(1));
                    imageShop2 = new File(finalSelectPaths.get(2));
                    iv_searchResult.setImageBitmap(bitmapList.get(0));
                    iv_shop1.setImageBitmap(bitmapList.get(1));
                    iv_shop2.setImageBitmap(bitmapList.get(2));
                    bitmapSearchResult = bitmapList.get(0);
                    bitmapShop1 = bitmapList.get(1);
                    bitmapShop2 = bitmapList.get(2);
                } else {
                    toast("请上传任务开始后的图片");
                    return;
                }
            } else if (step == 2) {
                if (maxNum == 4) {
                    if ((dateList.get(0).getTime() - date1.getTime()) / 1000 > 0 && (dateList.get(1)
                                                                                             .getTime() - date1
                            .getTime()) / 1000 > 0 && (dateList.get(2)
                                                               .getTime() - date1.getTime()) / 1000 > 0 && (dateList
                            .get(3)
                            .getTime() - date1.getTime()) / 1000 > 0) {
                        if ((dateList.get(3).getTime() - dateList.get(2).getTime()) / 1000 > 180) {
                            imageStoreShop1 = new File(finalSelectPaths.get(0));
                            imageStoreShop2 = new File(finalSelectPaths.get(1));
                            imageTargetGoodsStart = new File(finalSelectPaths.get(2));
                            imageTargetGoodsEnd = new File(finalSelectPaths.get(3));
                            iv_storeShop1.setImageBitmap(bitmapList.get(0));
                            iv_storeShop2.setImageBitmap(bitmapList.get(1));
                            iv_targetGoods_Start.setImageBitmap(bitmapList.get(2));
                            iv_targetGoods_End.setImageBitmap(bitmapList.get(3));
                            bitmapStoreShop1 = bitmapList.get(0);
                            bitmapStoreShop2 = bitmapList.get(1);
                            bitmapTargetGoodsStart = bitmapList.get(2);
                            bitmapTargetGoodsEnd = bitmapList.get(3);
                        } else {
                            toast("请按要求浏览商品");
                            return;
                        }
                    } else {
                        toast("请上传任务开始后的图片");
                        return;
                    }
                } else if (maxNum == 6) {
                    if ((dateList.get(0).getTime() - date1.getTime()) / 1000 > 0 && (dateList.get(1)
                                                                                             .getTime() - date1
                            .getTime()) / 1000 > 0 && (dateList.get(2)
                                                               .getTime() - date1.getTime()) / 1000 > 0 && (dateList
                            .get(3)
                            .getTime() - date1.getTime()) / 1000 > 0 && (dateList.get(4)
                                                                                 .getTime() - date1.getTime()) / 1000 > 0 && (dateList
                            .get(5)
                            .getTime() - date1.getTime()) / 1000 > 0) {
                        if ((dateList.get(3).getTime() - dateList.get(2).getTime()) / 1000 > 180) {
                            imageStoreShop1 = new File(finalSelectPaths.get(0));
                            imageStoreShop2 = new File(finalSelectPaths.get(1));
                            imageTargetGoodsStart = new File(finalSelectPaths.get(2));
                            imageTargetGoodsEnd = new File(finalSelectPaths.get(3));
                            imageFuJia1Header = new File(finalSelectPaths.get(4));
                            imageFuJia1Footer = new File(finalSelectPaths.get(5));
                            iv_storeShop1.setImageBitmap(bitmapList.get(0));
                            iv_storeShop2.setImageBitmap(bitmapList.get(1));
                            iv_targetGoods_Start.setImageBitmap(bitmapList.get(2));
                            iv_targetGoods_End.setImageBitmap(bitmapList.get(3));
                            iv_fuJia1_header.setImageBitmap(bitmapList.get(4));
                            iv_fuJia1_footer.setImageBitmap(bitmapList.get(5));
                            bitmapStoreShop1 = bitmapList.get(0);
                            bitmapStoreShop2 = bitmapList.get(1);
                            bitmapTargetGoodsStart = bitmapList.get(2);
                            bitmapTargetGoodsEnd = bitmapList.get(3);
                            bitmapFuJia1Header = bitmapList.get(4);
                            bitmapFuJia1Footer = bitmapList.get(5);
                        } else {
                            toast("请按要求浏览商品");
                            return;
                        }
                    } else {
                        toast("请上传任务开始后的图片");
                        return;
                    }

                } else if (maxNum == 8) {
                    if ((dateList.get(0).getTime() - date1.getTime()) / 1000 > 0 && (dateList.get(1)
                                                                                             .getTime() - date1
                            .getTime()) / 1000 > 0 && (dateList.get(2)
                                                               .getTime() - date1.getTime()) / 1000 > 0 && (dateList
                            .get(3)
                            .getTime() - date1.getTime()) / 1000 > 0 && (dateList.get(4)
                                                                                 .getTime() - date1.getTime()) / 1000 > 0 && (dateList
                            .get(5)
                            .getTime() - date1.getTime()) / 1000 > 0 && (dateList.get(6)
                                                                                 .getTime() - date1.getTime()) / 1000 > 0 && (dateList
                            .get(7)
                            .getTime() - date1.getTime()) / 1000 > 0) {
                        if ((dateList.get(3).getTime() - dateList.get(2).getTime()) / 1000 > 180) {
                            imageStoreShop1 = new File(finalSelectPaths.get(0));
                            imageStoreShop2 = new File(finalSelectPaths.get(1));
                            imageTargetGoodsStart = new File(finalSelectPaths.get(2));
                            imageTargetGoodsEnd = new File(finalSelectPaths.get(3));
                            imageFuJia1Header = new File(finalSelectPaths.get(4));
                            imageFuJia1Footer = new File(finalSelectPaths.get(5));
                            imageFuJia2Header = new File(finalSelectPaths.get(6));
                            imageFuJia2Footer = new File(finalSelectPaths.get(7));
                            iv_storeShop1.setImageBitmap(bitmapList.get(0));
                            iv_storeShop2.setImageBitmap(bitmapList.get(1));
                            iv_targetGoods_Start.setImageBitmap(bitmapList.get(2));
                            iv_targetGoods_End.setImageBitmap(bitmapList.get(3));
                            iv_fuJia1_header.setImageBitmap(bitmapList.get(4));
                            iv_fuJia1_footer.setImageBitmap(bitmapList.get(5));
                            iv_fuJia2_header.setImageBitmap(bitmapList.get(6));
                            iv_fuJia2_footer.setImageBitmap(bitmapList.get(7));
                            bitmapStoreShop1 = bitmapList.get(0);
                            bitmapStoreShop2 = bitmapList.get(1);
                            bitmapTargetGoodsStart = bitmapList.get(2);
                            bitmapTargetGoodsEnd = bitmapList.get(3);
                            bitmapFuJia1Header = bitmapList.get(4);
                            bitmapFuJia1Footer = bitmapList.get(5);
                            bitmapFuJia2Header = bitmapList.get(6);
                            bitmapFuJia2Footer = bitmapList.get(7);
                        } else {
                            toast("请按要求浏览商品");
                            return;
                        }
                    } else {
                        toast("请上传任务开始后的图片");
                        return;
                    }
                }

            } else if (step == 3) {
                if ((dateList.get(0).getTime() - date1.getTime()) / 1000 > 0 && (dateList.get(1)
                                                                                         .getTime() - date1
                        .getTime()) / 1000 > 0) {
                    imageChat = new File(finalSelectPaths.get(0));
                    imageOrderPay = new File(finalSelectPaths.get(1));
                    iv_chat.setImageBitmap(bitmapList.get(0));
                    iv_orderPay.setImageBitmap(bitmapList.get(1));
                    bitmapChat = bitmapList.get(0);
                    bitmapOrderPay = bitmapList.get(1);
                } else {
                    toast("请上传任务开始后的图片");
                    return;
                }
            }
        }

    }

    /***
     * 从相册中取图片
     */
    public void pickPhoto() {
        Intent intent = new Intent(Intent.ACTION_PICK);
        intent.setType("image/*");
        getActivity().startActivityForResult(intent, SELECT_IMAGE_RESULT_CODE);
    }

    /**
     * 拍照获取图片
     */
    public void takePhoto() {
        // 执行拍照前，应该先判断SD卡是否存在
        String SDState = Environment.getExternalStorageState();
        if (SDState.equals(Environment.MEDIA_MOUNTED)) {
            /**
             * 通过指定图片存储路径，解决部分机型onActivityResult回调 data返回为null的情况
             */
            //获取与应用相关联的路径
            imageFilePath = getActivity().getExternalFilesDir(Environment.DIRECTORY_PICTURES)
                                         .getAbsolutePath();
            if (ivState.equals("searchResult")) {
                imageFile = getImageFile(imageSearchResult, "searchResult");
            } else if (ivState.equals("shop1")) {
                imageFile = getImageFile(imageShop1, "imageShop1");
            } else if (ivState.equals("shop2")) {
                imageFile = getImageFile(imageShop2, "imageShop2");
            } else if (ivState.equals("storeShop1")) {
                imageFile = getImageFile(imageStoreShop1, "imageStoreShop1");
            } else if (ivState.equals("storeShop2")) {
                imageFile = getImageFile(imageStoreShop2, "imageStoreShop2");
            } else if (ivState.equals("targetGoodsStart")) {
                imageFile = getImageFile(imageTargetGoodsStart, "imageTargetGoodsStart");
            } else if (ivState.equals("targetGoodsEnd")) {
                imageFile = getImageFile(imageTargetGoodsEnd, "imageTargetGoodsEnd");
            } else if (ivState.equals("chat")) {
                imageFile = getImageFile(imageChat, "imageChat");
            } else if (ivState.equals("orderPay")) {
                imageFile = getImageFile(imageOrderPay, "imageOrderPay");
            }
            mImagePath = imageFile.getAbsolutePath();
            Uri imageFileUri = Uri.fromFile(imageFile);// 获取文件的Uri
            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            intent.putExtra(MediaStore.EXTRA_OUTPUT, imageFileUri);// 告诉相机拍摄完毕输出图片到指定的Uri
            getActivity().startActivityForResult(intent, SELECT_IMAGE_RESULT_CODE);
        } else {
            toast("内存卡不存在");
        }
    }

    public void upLoadImage(final String imageState) {
        ivState = imageState;
        pickPhoto();
    }

    public File getImageFile(File imageFile, String imageName) {
        String imagePath = "/" + imageName + ".jpg";
        imageFile = new File(imageFilePath, imagePath);
        if (imageFile.exists()) {
            imageFile.delete();
            imageFile = new File(imageFilePath, imagePath);
        }
        return imageFile;
    }

    @Override
    public boolean onBackPressed() {
        showCustomConfirmDialog("返回后台后将不保存所做操作，下次需要重新上传截图哦，确定要返回吗", "确定", "取消",
                                new SimpleDialog.OnSimpleClickListener() {
                                    @Override
                                    public void onClick(SimpleDialog simpleDialog) {
                                        if (isOverTime) {
                                            UIHelper.show(getActivity(), MainActivity.class, true);
                                        } else {
                                            orderFlag = "1";
                                            upDateTask();
                                        }
                                        simpleDialog.dismiss();
                                    }
                                }, new SimpleDialog.OnSimpleClickListener() {
                    @Override
                    public void onClick(SimpleDialog simpleDialog) {
                        simpleDialog.dismiss();
                    }
                }
        );
        return true;
    }

    private String checkMessage() {
        if (TextUtils.isEmpty(mOrderInfo.getUrl2()) && TextUtils.isEmpty(mOrderInfo.getUrl3())) {
            if (bitmapSearchResult == null || bitmapShop1 == null || bitmapShop2 == null ||
                    bitmapStoreShop1 == null || bitmapStoreShop2 == null || bitmapTargetGoodsStart == null ||
                    bitmapTargetGoodsEnd == null || bitmapChat == null || bitmapOrderPay == null)
                return "请选择要上传的照片";
        } else if (!TextUtils.isEmpty(mOrderInfo.getUrl2()) && TextUtils.isEmpty(
                mOrderInfo.getUrl3())) {
            if (bitmapSearchResult == null || bitmapShop1 == null || bitmapShop2 == null ||
                    bitmapStoreShop1 == null || bitmapStoreShop2 == null || bitmapTargetGoodsStart == null ||
                    bitmapTargetGoodsEnd == null || bitmapFuJia1Header == null || bitmapFuJia1Footer == null || bitmapChat == null ||
                    bitmapOrderPay == null) return "请选择要上传的照片";
        } else if (!TextUtils.isEmpty(mOrderInfo.getUrl2()) && !TextUtils.isEmpty(
                mOrderInfo.getUrl3())) {
            if (bitmapSearchResult == null || bitmapShop1 == null || bitmapShop2 == null ||
                    bitmapStoreShop1 == null || bitmapStoreShop2 == null || bitmapTargetGoodsStart == null ||
                    bitmapTargetGoodsEnd == null || bitmapFuJia1Header == null || bitmapFuJia1Footer == null || bitmapFuJia2Header == null || bitmapFuJia2Footer == null || bitmapChat == null ||
                    bitmapOrderPay == null) return "请选择要上传的照片";
        }

        etMoney = et_money.getText().toString().trim();
        if (TextUtils.isEmpty(etMoney)) return "请输入实付金额";
        return "";
    }

    private void selectGallery() {
        if (bitmapList != null || bitmapList.size() > 0) {
            bitmapList.clear();
        }
        if (finalSelectPaths != null || finalSelectPaths.size() > 0) {
            finalSelectPaths.clear();
        }
        if (dateList != null || dateList.size() > 0) {
            dateList.clear();
        }
        Intent intent = new Intent(mActivity, MultiImageSelectorActivity.class);
        // 是否显示拍摄图片,不显示
        intent.putExtra(MultiImageSelectorActivity.EXTRA_SHOW_CAMERA, false);
        // 最大可选择图片数量
        intent.putExtra(MultiImageSelectorActivity.EXTRA_SELECT_COUNT, maxNum);
        // 选择模式,选取多张
        intent.putExtra(MultiImageSelectorActivity.EXTRA_SELECT_MODE,
                        MultiImageSelectorActivity.MODE_MULTI
        );
        //        // 默认选择
        //        if (mSelectPath != null && mSelectPath.size() > 0) {
        //            intent.putExtra(MultiImageSelectorActivity.EXTRA_DEFAULT_SELECTED_LIST, mSelectPath);
        //        }
        getActivity().startActivityForResult(intent, REQUEST_IMAGE);
    }


    private void upDateTask() {
        ApiHttpClient.setUpdateTask(this, orderid, orderFlag,
                                    new JsonCallback<String>(String.class, true) {

                                        @Override
                                        public void onBefore(Request request) {
                                            super.onBefore(request);
                                        }

                                        @Override
                                        public void onError(Call call, Exception e) {
                                            toast("网络连接失败,请稍后再试");
                                        }

                                        @Override
                                        public void onResponse(ResponseInfo<String> response) {
                                            int code = response.getCode();
                                            String message = response.getMessage();
                                            if (code == 1) {
                                                showWarnDialog(message);
                                                return;
                                            }
                                            Map<String, Object> _map = response.getFirstEntity();
                                            Bundle args = new Bundle();
                                            if (taskState.equals("1")) {
                                                args.putSerializable("info", mOrderInfo);
                                                args.putString("state", "orderTask");
                                                args.putString("time", addtime);
                                                args.putString("orderid", orderid);
                                                args.putString("buyerid", buyerid);
                                                UIHelper.showMpTaoBaoTask2(mActivity, args);
                                            } else if (taskState.equals("2")) {
                                                args.putSerializable("info", taskOperateInfo);
                                                args.putString("state", "operate");
                                                args.putString("time", addtime);
                                                UIHelper.showMpTaoBaoTask2(mActivity, args);
                                            } else if (taskState.equals("3")) {
                                                args.putString("way", "2");
                                                UIHelper.showAdvancesUnComplate(mActivity, args);
                                            }
                                            finish();
                                        }

                                        @Override
                                        public void onAfter() {
                                            super.onAfter();
                                        }
                                    }
        );
    }


    private void insertDianFuTask2() {
        ApiHttpClient.insertDianFuTask2(OperationTaskFragment.this, cid, orderid,
                                        userInfo.getWebzzCmsBuyerInfo().getUserid(), etMoney,
                                        imageSearchResult, imageShop1, imageShop2, imageStoreShop1,
                                        imageStoreShop2, imageTargetGoodsStart, imageTargetGoodsEnd,
                                        imageChat, imageOrderPay, addtime,
                                        new JsonCallback<String>(String.class, true) {

                                            @Override
                                            public void onBefore(Request request) {
                                                super.onBefore(request);
                                                showWaitingDialog();
                                            }

                                            @Override
                                            public void onError(Call call, Exception e) {
                                                toast("网络异常，请检查后再试");
                                            }

                                            @Override
                                            public void onResponse(ResponseInfo<String> response) {
                                                int code = response.getCode();
                                                if (code == 1) {
                                                    showWarnDialog(response.getMessage());
                                                    return;
                                                }
                                                toast("任务提交成功");
                                                orderFlag = "3";
                                                taskState = "3";
                                                upDateTask();
                                            }

                                            @Override
                                            public void onAfter() {
                                                super.onAfter();
                                                hideWaitingDialog();
                                            }
                                        }
        );
    }

    private void insertDianFuTask2Six() {
        ApiHttpClient.insertDianFuTask2Six(OperationTaskFragment.this, cid, orderid,
                                           userInfo.getWebzzCmsBuyerInfo().getUserid(), etMoney,
                                           imageSearchResult, imageShop1, imageShop2,
                                           imageStoreShop1, imageStoreShop2, imageTargetGoodsStart,
                                           imageTargetGoodsEnd, imageChat, imageOrderPay,
                                           imageFuJia1Header, imageFuJia1Footer, addtime,
                                           new JsonCallback<String>(String.class, true) {

                                               @Override
                                               public void onBefore(Request request) {
                                                   super.onBefore(request);
                                                   showWaitingDialog();
                                               }

                                               @Override
                                               public void onError(Call call, Exception e) {
                                                   toast("网络异常，请检查后再试");
                                               }

                                               @Override
                                               public void onResponse(
                                                       ResponseInfo<String> response
                                               ) {
                                                   int code = response.getCode();
                                                   if (code == 1) {
                                                       showWarnDialog(response.getMessage());
                                                       return;
                                                   }
                                                   toast("任务提交成功");
                                                   orderFlag = "3";
                                                   taskState = "3";
                                                   upDateTask();
                                               }

                                               @Override
                                               public void onAfter() {
                                                   super.onAfter();
                                                   hideWaitingDialog();
                                               }
                                           }
        );
    }

    private void insertDianFuTask2Eight() {
        ApiHttpClient.insertDianFuTask2Eight(OperationTaskFragment.this, cid, orderid,
                                             userInfo.getWebzzCmsBuyerInfo().getUserid(), etMoney,
                                             imageSearchResult, imageShop1, imageShop2,
                                             imageStoreShop1, imageStoreShop2,
                                             imageTargetGoodsStart, imageTargetGoodsEnd,
                                             imageFuJia1Header, imageFuJia1Footer,
                                             imageFuJia2Header, imageFuJia2Footer, imageChat,
                                             imageOrderPay, addtime,
                                             new JsonCallback<String>(String.class, true) {

                                                 @Override
                                                 public void onBefore(Request request) {
                                                     super.onBefore(request);
                                                     showWaitingDialog();
                                                 }

                                                 @Override
                                                 public void onError(Call call, Exception e) {
                                                     toast("网络异常，请检查后再试");
                                                 }

                                                 @Override
                                                 public void onResponse(
                                                         ResponseInfo<String> response
                                                 ) {
                                                     int code = response.getCode();
                                                     if (code == 1) {
                                                         showWarnDialog(response.getMessage());
                                                         return;
                                                     }
                                                     toast("任务提交成功");
                                                     orderFlag = "3";
                                                     taskState = "3";
                                                     upDateTask();
                                                 }

                                                 @Override
                                                 public void onAfter() {
                                                     super.onAfter();
                                                     hideWaitingDialog();
                                                 }
                                             }
        );
    }

    private void cancelTask() {
        ApiHttpClient.cancelTak(this, cid, orderid, taskCode, endTime, "任务取消了", buyerid, "001",
                                account, sellerID, "1",
                                new JsonCallback<String>(String.class, true) {

                                    @Override
                                    public void onBefore(Request request) {
                                        super.onBefore(request);
                                    }

                                    @Override
                                    public void onError(Call call, Exception e) {
                                        toast("网络连接失败,请稍后再试");
                                    }

                                    @Override
                                    public void onResponse(ResponseInfo<String> response) {
                                        int code = response.getCode();
                                        String message = response.getMessage();
                                        if (code == 1) {
                                            showWarnDialog(message);
                                            return;
                                        }
                                        Map<String, Object> _map = response.getFirstEntity();
                                        UIHelper.show(getActivity(), MainActivity.class, true);
                                        finish();
                                    }

                                    @Override
                                    public void onAfter() {
                                        super.onAfter();
                                    }
                                }
        );
    }

    public void intWatch() {
        et_money.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                et_money.setTextColor(getResources().getColor(R.color.textColorThird));
            }
        });

    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        timer.cancel();
    }
}
